package demo3;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-02-09
 * Time: 22:00
 */
interface IShape{
    int a = 10; //因为默认是 public static final 修饰的（常量）必须要初始化

    void draw(); //抽象方法

    default public  void func(){
        System.out.println("default 修饰的func()方法");
    }
}

class Rect implements IShape {
    @Override
    public void draw() {
        System.out.println("♦");
    }

    @Override
    public void func() {
        System.out.println("重写接口中的func()方法");
    }
}

class Flower implements IShape {
    @Override
    public void draw() {
        System.out.println("❀");
    }
}
public class Test {

    public static void drawMap(IShape iShape){
        iShape.draw();
    }
    public static void main(String[] args) {
        //向上转型
        IShape iShape = new Rect();
        drawMap(iShape);
        //调用子类 Rect 中重写的func方法
        iShape.func();

        Flower flower = new Flower();
        drawMap(flower);
    }
}
